package com.closer.service.biz.langgraph4j.service;

import com.closer.service.biz.langgraph4j.tools.ImageSearchTool;
import com.closer.service.biz.langgraph4j.tools.LogoGeneratorTool;
import com.closer.service.biz.langgraph4j.tools.MermaidDiagramTool;
import com.closer.service.biz.langgraph4j.tools.UndrawIllustrationTool;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class ImageCollectionServiceFactory {

    private final ChatModel chatModel;

    private final ImageSearchTool imageSearchTool;

    private final UndrawIllustrationTool undrawIllustrationTool;

    private final MermaidDiagramTool mermaidDiagramTool;

    private final LogoGeneratorTool logoGeneratorTool;

    public ImageCollectionServiceFactory(
            @Qualifier("openAiChatModel") ChatModel chatModel,
            ImageSearchTool imageSearchTool,
            UndrawIllustrationTool undrawIllustrationTool,
            MermaidDiagramTool mermaidDiagramTool,
            LogoGeneratorTool logoGeneratorTool
    ) {
        this.chatModel = chatModel;
        this.imageSearchTool = imageSearchTool;
        this.undrawIllustrationTool = undrawIllustrationTool;
        this.mermaidDiagramTool = mermaidDiagramTool;
        this.logoGeneratorTool = logoGeneratorTool;
    }

    /**
     * 创建图片收集 AI 服务
     */
    @Bean
    public ImageCollectionService createImageCollectionService() {
        return AiServices.builder(ImageCollectionService.class)
                .chatModel(chatModel)
                .tools(
                        imageSearchTool,
                        undrawIllustrationTool,
                        mermaidDiagramTool,
                        logoGeneratorTool
                )
                .build();
    }
}
